package com.enjoylearning.content.api;


import com.enjoylearning.content.model.dto.BindTeachplanMediaDto;
import com.enjoylearning.content.model.dto.SaveTeachplanDto;
import com.enjoylearning.content.model.dto.TeachplanDto;
import com.enjoylearning.content.service.TeachPlanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TeachPlanController {

    @Autowired
    private TeachPlanService teachPlanService;

    //查询课程计划
    @ApiOperation("查询课程计划")
    @GetMapping("/teachplan/{Id}/tree-nodes")
    public List<TeachplanDto> selectTeachPlanById(@PathVariable Long Id) {
        List<TeachplanDto> teachplanDtos = teachPlanService.selectTeachplanById(Id);
        return teachplanDtos;
    }

    //新增或修改课程计划
    @ApiOperation("新增课程计划或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        teachPlanService.saveTeachplan(saveTeachplanDto);
    }

    @ApiOperation("删除课程计划")
    @DeleteMapping("/teachplan/{id}")
    public void deleteTeachplan(@PathVariable Long id) {
        teachPlanService.deleteTeachplan(id);
    }

    @ApiOperation("向下移动课程")
    @PostMapping("/teachplan/movedown/{id}")
    public void movedownTeachplan(@PathVariable Long id) {
        teachPlanService.moveDownTeachplan(id);
    }

    @ApiOperation("向上移动课程")
    @PostMapping("/teachplan/moveup/{id}")
    public void moveupTeachplan(@PathVariable Long id) {
        teachPlanService.moveupTeachplan(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachPlanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除媒资信息绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deleteAssociationMedia(@PathVariable String teachPlanId, @PathVariable String  mediaId){
        teachPlanService.deleteAssociationMedia(teachPlanId,mediaId);
    }

}
